import java.util.Hashtable;

class P671 {

	public static void main(String[] args) {
		StringBuffer answer = new StringBuffer();
		int cases = Integer.parseInt(readLn());
//		String line1 = readLn();
		for (int k = 0; k < cases; k++) {
//		while(!line1.equals("#")) {
			readLn();
			Hashtable dictionary = new Hashtable();
			String[] dic = new String[10000];
			int dicLength = 0;
			String line = readLn();
			while(!line.equals("#")) {
				dictionary.put(line, "#");
				dic[dicLength] = line;
				dicLength++;
				line = readLn();
			}
			line = readLn();
			while(!line.equals("#")) {
//				System.out.print(line);
				answer.append(line);
//				Vector answers = new Vector();
//				int length = dictionary.size();
				boolean correct = dictionary.get(line) != null; 
				if (!correct) {
//					StringBuffer sb = new StringBuffer(":");
					answer.append(":");
					for (int w = 0; w < dicLength; w++) {
						String s = dic[w];
						
						
//							if (LD(s, line) == 1/) {
						if (palavrasOK(s, line)) {
								answer.append(" " + s);
							}
					}
					answer.append("\n");
//					System.out.println(sb.toString());
					
				}
				else {
//					System.out.println(" is correct");
					answer.append(" is correct\n");
				}
				line = readLn();
			}
//			System.out.println();
			if (k + 1 != cases)	answer.append("\n");
//			line1 = readLn();
		}
		System.out.print(answer.toString());
	}
	
//	m[i,j] = d(s1[1..i], s2[1..j])
//
//	m[0,0] = 0
//	m[i,0] = i,  i=1..|s1|
//	m[0,j] = j,  j=1..|s2|
//
//	m[i,j] = min(m[i-1,j-1]
//	             + if s1[i]=s2[j] then 0 else 1 fi,
//	             m[i-1, j] + 1,
//	             m[i, j-1] + 1 ),  i=1..|s1|, j=1..|s2|


	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

//	****************************
	  // Get minimum of three values
	  //****************************

	  private static int Minimum (int a, int b, int c) {
	  int mi;

	    mi = a;
	    if (b < mi) {
	      mi = b;
	    }
	    if (c < mi) {
	      mi = c;
	    }
	    return mi;

	  }

	  //*****************************
	  // Compute Levenshtein distance
	  //*****************************

	  public static int LD (String s, String t) {
	  int d[][]; // matrix
	  int n; // length of s
	  int m; // length of t
	  int i; // iterates through s
	  int j; // iterates through t
	  char s_i; // ith character of s
	  char t_j; // jth character of t
	  int cost; // cost
	    // Step 1
	    n = s.length ();
	    m = t.length ();
	    if (n == 0) {
	      return m;
	    }
	    if (m == 0) {
	      return n;
	    }
	    int x = n - m;
	    if (x < 0) {
	    	x = x * -1;
	    }
	    if (x > 1) {
	    	return 45;
	    }
	    d = new int[n+1][m+1];
	    // Step 2
	    for (i = 0; i <= n; i++) {
	      d[i][0] = i;
	    }
	    for (j = 0; j <= m; j++) {
	      d[0][j] = j;
	    }
	    // Step 3
	    for (i = 1; i <= n; i++) {
	      s_i = s.charAt (i - 1);
	      // Step 4
	      for (j = 1; j <= m; j++) {
	        t_j = t.charAt (j - 1);
	        // Step 5
	        if (s_i == t_j) {
	          cost = 0;
	        }
	        else {
	          cost = 1;
	        }
	        // Step 6
	        d[i][j] = Minimum (d[i-1][j]+1, d[i][j-1]+1, d[i-1][j-1] + cost);
	      }
	    }
	    // Step 7
	    return d[n][m];
	  }


	  private static boolean palavrasOK(String a, String b) {
	         if (a.length() - b.length() > 1 || a.length() - b.length() < -1)
	               return false;
	         boolean erro = false;
	         for (int i = 0, j = 0; i < a.length() && j < b.length();) {
	              if (a.charAt(i) != b.charAt(j)) {
	                    if (erro) {
	                         return false;
	                     }
	                    erro = true;
	                    if (i != a.length()-1 && a.charAt(i+1) == b.charAt(j) && a.length()-1 == b.length()) {
	                         // removendo
	                          i++;
	                    } else if (j != b.length()-1 && a.charAt(i) == b.charAt(j+1) && a.length() == b.length()-1) {
	                         // inserindo
	                          j++;
	                    } else if (a.length() == b.length()) {
	                         // trocando
	                         i++; j++;
	                    } else {
	                         return false;
	                     }
	              } else {
	                    i++; j++;
	               }
	          }
	         return true;
	     }
	
}
